package top.rainf.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.rainf.domain.vo.BoardMessage;
import top.rainf.mapper.BoardMessageMapper;
import top.rainf.service.IBoardMessageService;
import top.rainf.util.PagerUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 星环
 * @date 2023/5/10 16:29:18
 * @description
 */
@Service
public class BoardMessageService implements IBoardMessageService {
    @Autowired
    BoardMessageMapper boardMessageMapper;

    @Override
    public List<BoardMessage> selectAll() {
        return boardMessageMapper.selectAll();
    }

    /**
     * 阅读公告访问该方法，因此返回对应数据，并增加阅读量
     * @param id 要查询的公告id
     * @return 公告实体
     */
    @Override
    public BoardMessage readOne(int id) {
        BoardMessage boardMessage = boardMessageMapper.selectByIdFull(id);
        if(boardMessage != null){
            boardMessageMapper.addOneReadCountById(id);
        }
        return boardMessage;
    }

    @Override
    public boolean deleteOneById(int id) {
        return false;
    }

    @Override
    public boolean deleteAll(List<Integer> idList) {
        return false;
    }

    @Override
    public boolean updateById(BoardMessage boardMessage) {
        return false;
    }

    @Override
    public BoardMessage prevOne(int id) {
        return boardMessageMapper.selectPrevOneIdAndTitleById(id);
    }

    @Override
    public BoardMessage nextOne(int id) {
        return boardMessageMapper.selectNextOneIdAndTitleById(id);
    }

    @Override
    public List<BoardMessage> selectRecentN(int num) {
        return boardMessageMapper.selectRecentN(num);
    }

    @Override
    public List<BoardMessage> selectPage(int numPerPage, int pageNum) {
        return boardMessageMapper.selectPage((pageNum -1) * numPerPage,numPerPage);
    }

    @Override
    public List<String> getPageListStr(int recordPerPage, int curPage) {
        int totalNum = boardMessageMapper.selectRecordCount();
        return PagerUtil.getPageListStr(recordPerPage,curPage,totalNum);
    }
}
